﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using System.IO;


namespace DLL.Entities
{
    public class Read_Write
    {

        public static bool WriteXML(object savedObj, string fileToSave, XmlSerializer serializer)
        {
            try
            {
                string dir = "..\\..\\..\\DLL\\XML\\" + fileToSave;
                TextWriter textWriter = new StreamWriter(dir);
                serializer.Serialize(textWriter, savedObj);
                textWriter.Close();
                return true;
            }
            catch (Exception ex)
            {
                Utility.LogFile(ex.ToString());
                return false;
            }
        }

        
        public static bool ReadXML(out object obj, string fileToRead, XmlSerializer serializer)
        {
            try
            {
                string dir = "..\\..\\..\\DLL\\XML\\" + fileToRead;
                XmlReader reader = new XmlTextReader(dir);
                obj = serializer.Deserialize(reader);
                reader.Close();
                return true;
            }
            catch (Exception ex)
            {
                Utility.LogFile(ex.ToString());
                obj = null;
                return false;
            }
        }
         
    }
}
